package com.xncoding.tomcat.socket;
import java.io.*;
import java.net.*;


public class Server {

    public static String readline = null;
    public static String inTemp = null;
    public static String turnLine = "";
    public static final String client = "客户端:";
    public static final String server = "服务端:";
    public static final int PORT = 8090;

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(PORT);
        System.out.println("服务端已经准备好了");
        Socket socket = serverSocket.accept();

        BufferedReader systemIn = new BufferedReader(new InputStreamReader(System.in));
        BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        PrintWriter socketOut = new PrintWriter(socket.getOutputStream());
        while (true) {
            inTemp = socketIn.readLine();
            if (inTemp != null &&inTemp.contains("over")) {
                systemIn.close();
                socketIn.close();
                socketOut.close();
                socket.close();
                serverSocket.close();
            }
            System.out.println(client + inTemp);
            System.out.print(server);

            readline = systemIn.readLine();

            socketOut.println(readline);
            socketOut.flush();
        }
    }
}
